package com.meichis.yndms.adapter;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.widget.Toast;

import com.meichis.mcsappframework.adapter.recyclerview.CommonAdapter;
import com.meichis.mcsappframework.adapter.recyclerview.base.ViewHolder;
import com.meichis.yndms.R;
import com.meichis.yndms.model.StayInOrder;

import java.util.List;

/**
 * @author xmy
 * @title
 * @remake
 * @create 2022-05-19 21:37
 */
public class StayInOrderAdapter extends CommonAdapter<StayInOrder> {

    public StayInOrderAdapter(Context context, int layoutId, List<StayInOrder> datas) {
        super(context, layoutId, datas);
    }

    @Override
    protected void convert(ViewHolder holder, StayInOrder stayInOrder, int position) {
        holder.setText(R.id.tv_code, stayInOrder.getOrderNo());
        holder.setText(R.id.tv_from, stayInOrder.getRepositoryName());
        holder.setText(R.id.tv_arrival, stayInOrder.getStorageName());
        holder.setText(R.id.tv_time, stayInOrder.getOutDt());
        holder.setText(R.id.tv_name, stayInOrder.getDriverName() + " " + stayInOrder.getMobile());
        holder.setText(R.id.tv_info, "数量 " + stayInOrder.getQuantity() + "件  " + "重量 " + stayInOrder.getWeight() + "吨");

        holder.setOnClickListener(R.id.tv_code, v -> {
            ClipboardManager manager = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData mClipData = ClipData.newPlainText("Label", stayInOrder.getOrderNo());
            manager.setPrimaryClip(mClipData);
            Toast.makeText(mContext, "订单编号复制成功", Toast.LENGTH_SHORT).show();
        });

        holder.setOnClickListener(R.id.tv_name, v -> {
            Intent Intent = new Intent(android.content.Intent.ACTION_DIAL, Uri.parse("tel:" + stayInOrder.getMobile()));
            mContext.startActivity(Intent);
        });

    }
}
